<template>
  <div class="table-page">
    <a-form label-align="right" auto-label-width :model="form" class="form">
      <a-row :gutter="16" wrap>
        <a-col :xs="12" :md="12" :lg="8" :xl="6" :xxl="6">
          <a-form-item field="username" label="账号">
            <a-input v-model="form.username" placeholder="请输入账号" />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-space>
            <a-button type="primary" @click="getTableData">
              <template #icon>
                <icon-search />
              </template>
              <template #default>查询</template>
            </a-button>
          </a-space>
        </a-col>
      </a-row>
    </a-form>

    <section class="table-box">
      <a-table
        row-key="id"
        size="small"
        page-position="bl"
        :bordered="{ cell: true }"
        :loading="loading"
        :data="tableData"
        :scroll="{ x: '100%', y: '100%', minWidth: 1000 }"
        :pagination="{ showPageSize: true, showTotal: true, total: total, current: current, pageSize: pageSize }"
        @page-change="changeCurrent"
        @page-size-change="changePageSize"
      >
        <template #columns>
          <a-table-column title="备ID注" :width="110" data-index="id"></a-table-column>
          <a-table-column title="管理员ID" :width="110" data-index="admin_id"></a-table-column>
          <a-table-column title="账号" data-index="username">
            <template #cell="{ record }">
              {{ record.Admin?.username }}
            </template>
          </a-table-column>
          <a-table-column title="手机号" data-index="mobile">
            <template #cell="{ record }">
              {{ record.Admin?.mobile }}
            </template>
          </a-table-column>
          <a-table-column title="部门名称" :width="140" data-index="admin_role_name">
            <template #cell="{ record }">
              {{ record.Admin?.admin_role_name }}
            </template>
          </a-table-column>
          <a-table-column title="操作内容" data-index="operation_address"></a-table-column>
          <a-table-column title="操作时间" data-index="create_time"></a-table-column>
        </template>
      </a-table>
    </section>
  </div>
</template>

<script setup lang="ts" name="MainTable">
import { reactive, ref } from 'vue'
import { usePagination } from '@/hooks'
import { getlogList } from '@/apis'
import { useRouter } from 'vue-router'
import { Message } from '@arco-design/web-vue'
import { format } from 'date-fns'

const router = useRouter()
const form = reactive({
  username: ''
})
const loading = ref(false)
const tableData = ref([])

const { current, pageSize, total, changeCurrent, changePageSize, setTotal } = usePagination(() => getTableData())

const getTableData = async () => {
  loading.value = true
  const where = {
    page: current.value,
    limit: pageSize.value,
    ...form
  }
  const res = await getlogList(where)
  let resData = JSON.parse(res)

  if (resData.code === 200) {
    tableData.value = resData.result.data
    setTotal(resData.result.total)
    loading.value = false
  } else {
    loading.value = false
  }
}

getTableData()
</script>

<style lang="scss" scoped>
:deep(.arco-grid) {
  flex-wrap: wrap;
}
:deep(.arco-grid-item) {
  min-width: 250px;
}
:deep(.arco-alert-success) {
  padding: 14px 16px;
  border-color: rgb(var(--success-6));
  background-color: rgba(var(--success-6), 0.08);
  .arco-alert-content {
    color: rgb(var(--success-6));
    font-size: 12px;
  }
}
.table-page {
  height: 100%;
  overflow: hidden;
  margin: $margin;
  background: var(--color-bg-1);
  padding: $padding;
  padding-bottom: 0;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  .form {
    margin-top: 12px;
    :deep(.arco-form-item) {
      margin-bottom: 10px;
    }
  }
  .table-box {
    flex: 1;
    overflow: hidden;
    margin-top: 12px;
    padding-bottom: 16px;
  }
}
</style>
